define(function(require,exports,modlue){
	

	var orderVal = $("#order li.current a").attr("data-val");
	var loading = "order="+orderVal;
	ajaxUrl(loading);//初始化调用
	//排序
	$("#order li").click(function(){
		var val = parseInt($(this).find("a").attr("data-val"));
		if($(this).hasClass("current")){
			if(val > 0){
				val = 0 - val;
				$(this).find("a").attr("data-val",val);
				$(this).find("i").removeClass("descend").addClass("normal");
			}
			else if(val < 0)
			{
				val = 0-val;
				$(this).find("a").attr("data-val",val);
				$(this).find("i").removeClass("normal").addClass("descend");
			}
		}
		else{
			$(this).find("i").removeClass("normal").addClass("descend");
		}
		$(this).addClass("current").siblings().removeClass("current");
		var param = "aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&queryStatus="+$("#status a.current").attr("data-val")+"&order="+val+"&searchName="+encodeURIComponent($("#name").val());
		ajaxUrl(param);
		
	});

	//利率搜索
	$("#aprSearch a").click(function(){
		$(this).addClass("current").siblings().removeClass("current");
		var param = "aprSearch="+$(this).data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&queryStatus="+$("#status a.current").attr("data-val")+"&order="+$("#order li.current a").attr("data-val")+"&searchName="+encodeURIComponent($("#name").val());
		ajaxUrl(param);
	});
	
	//金额搜索
	$("#moneySearch a").click(function(){
		$(this).addClass("current").siblings().removeClass("current");
		var search = "aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$(this).data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&queryStatus="+$("#status a.current").attr("data-val")+"&order="+$("#order li.current a").attr("data-val")+"&searchName="+encodeURIComponent($("#name").val());
		ajaxUrl(search);
	});
	
	//期限搜索
	$("#timeSearch a").click(function(){
		$(this).addClass("current").siblings().removeClass("current");
		var param ="aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$(this).data("val")+"&queryStatus="+$("#status a.current").attr("data-val")+"&order="+$("#order li.current a").attr("data-val")+"&searchName="+encodeURIComponent($("#name").val());
		ajaxUrl(param);
	});
	
	//状态搜索
	$("#status a").click(function(){
		$(this).addClass("current").siblings().removeClass("current");
		var param = "aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&queryStatus="+$(this).attr("data-val")+"&order="+$("#order li.current a").attr("data-val")+"&searchName="+encodeURIComponent($("#name").val());
		ajaxUrl(param);
	});
	
	//点击搜索调用
	$(".searchBtn").click(function(){
		var search = "aprSearch="+$("#aprSearch a.current").data("val")+"&moneySearch="+$("#moneySearch a.current").data("val")+"&timeSearch="+$("#timeSearch a.current").data("val")+"&queryStatus="+$("#status a.current").attr("data-val")+"&order="+$("#order li.current a").attr("data-val")+"&searchName="+encodeURIComponent($("#name").val());
		ajaxUrl(search);
	});

	//通用显示函数
	function ajaxUrl(param){
		$.ajax({
		type:'get',
		url:'/flow/flowIndexJson.html?' + param + '&randomTime=' + (new Date()).getTime(),
		dataType:'json',
		success:function(json){
			//总记录数
			$(".quickBar span em").html(json.data.page.total);			
			var tpl = require('../../tpl/flowList.tpl');
			var template = Handlebars.compile(tpl);
			var html = template(json);
			$('.investListBox').html(html);
			//偶数行增加背景颜色
			$(".investItem:odd").addClass("investItemBg");
			//不同的进度，更换成不同的颜色
			require.async('/plugins/jquery.knob/jquery.knob.min',function(){
				$('.knob').each(function(){
					var val = parseInt($(this).val());
					if(val <= 25 && val > 0)
					{
						$(this).attr("data-fgColor","#5bc0de");
					}
					else if(val == 0)
					{
						$(this).attr("data-fgColor","#eee");
					}
					else if(val > 25 && val <= 50)
					{
						$(this).attr("data-fgColor","#12adff");
					}
					else if(val > 50 && val < 100)
					{
						$(this).attr("data-fgColor","#28b726");
					}
					else
					{
						var isIE = function(ver){
						    var b = document.createElement('b');
						    b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->';
						    return b.getElementsByTagName('i').length === 1;
						};
						if(isIE(8)){
						    $(this).next().addClass("investComplete100");
						}
						$(this).attr("data-fgColor","#c83e41");
					}
				});
				$('.knob').knob({
					'width':50,
					'height':50,
					'thickness':.2
				});
			});
					
			
				//分页插件
				if(json.data.page.pages > 0)
				{
					require.async(['/plugins/pager/pager.css','/plugins/pager/pager'],function(){
						kkpager.generPageHtml({
							pno : json.data.page.currentPage,//当前页码
							total : json.data.page.pages,//总页码
							totalRecords : json.data.page.total,//总数据条数
							isShowFirstPageBtn	: false, 
							isShowLastPageBtn	: false, 
							isShowTotalPage 	: false, 
							isShowTotalRecords 	: false, 
							isGoPage 			: false,
							lang:{
								prePageText				: '<',
								nextPageText			: '>'
							},
							mode:'click',//click模式匹配getHref 和 click
							click:function(n,total,totalRecords){
					        	$.ajax({
					        		type:"get",
					        		url:"/flow/flowIndexJson.html?" + param + "&randomTime=" + (new Date()).getTime() + "&page=" + n,
					        		dataType:"json",//这个必不可少，如果缺少，导致传回来的不是json格式
					        		success:function(json){
				        				var tpl = require('../../tpl/flowList.tpl');
										var template = Handlebars.compile(tpl);
										var html    = template(json);
										$('.investListBox').html(html);
										//偶数行增加背景颜色
										$(".investItem:odd").addClass("investItemBg");
										//判断是否是IE浏览器
										if(!+[1,]) require('/plugins/jquery.knob/excanvas');
										//不同的进度，更换成不同的颜色
										require.async('/plugins/jquery.knob/jquery.knob.min',function(){
											$('.knob').each(function(){
												var val = parseInt($(this).val());
												if(val <= 25 && val > 0)
												{
													$(this).attr("data-fgColor","#5bc0de");
												}
												else if(val == 0)
												{
													$(this).attr("data-fgColor","#eee");
												}
												else if(val > 25 && val <= 50)
												{
													$(this).attr("data-fgColor","#12adff");
												}
												else if(val > 50 && val < 100)
												{
													$(this).attr("data-fgColor","#28b726");
												}
												else
												{
													var isIE = function(ver){
													    var b = document.createElement('b');
													    b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->';
													    return b.getElementsByTagName('i').length === 1;
													};
													if(isIE(8)){
													    $(this).next().addClass("investComplete100");
													}
													$(this).attr("data-fgColor","#c83e41");
												}
											});
											$('.knob').knob({
												'width':50,
					   							'height':50,
					   							'thickness':.2
											});
										});											
					        		}
					        	});
								this.selectPage(n); //处理完后可以手动条用selectPage进行页码选中切换
							}
						});
					});
				}else{
					$("#kkpager").html('暂无数据');
				}
			}
		});	
	}
	
	//翻页置顶
	require.async("commonJS/rollTo",function(){
		$("#kkpager").rollTo({
			oFinish: ".investList ", //要滚动到的元素
			sSpeed: "300",  //滚动速度
			bMonitor: false, //是否楼层监听
			sClass: "", //楼层监听时需要添加的样式
			iBias:-18,
			fnAdditional: "" //追加方法
		});
	})	
	
});